﻿using System;
using System.Threading;
using System.Windows.Forms;
using TimerUppercut.Forms;
using TimerUppercut.Utils;

namespace TimerUppercut
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionHandler().ApplicationThreadException;

            bool newInstance;
            var mutex = new Mutex(false, "Local\\" + EventUtility.AssemblyVersion, out newInstance);
            if (newInstance)
            {
                Application.Run(new TimerForm());
            }
            else
            {
                MessageBox.Show("Only one instance can be run at a time", string.Format("{0} {1}", AssemblyInfo.AssemblyProduct, AssemblyInfo.AssemblyVersion), MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            GC.KeepAlive(mutex);
        }
    }
}